package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.ConmitData_Bean;
import cn.xfdzx.android.apps.shop.bean.GetJieguoBeen;
import cn.xfdzx.android.apps.shop.bean.Store_informationBean;
import cn.xfdzx.android.apps.shop.contract.InformationContract;
import cn.xfdzx.android.apps.shop.model.InformationModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * author : hjl
 * date   : 2021/6/3
 * desc   :
 * version:
 */
public class InformationPresenter extends BasePresenter<InformationContract.View> implements InformationContract.Presenter {
    private InformationContract.Model model;

    public InformationPresenter() {
        model = new InformationModel();
    }

    @Override
    public void forstate(String s) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.forstate()
                .compose(RxScheduler.<Store_informationBean>Flo_io_main())
                .as(mView.<Store_informationBean>bindAutoDispose())
                .subscribe(new Consumer<Store_informationBean>() {
                    @Override
                    public void accept(Store_informationBean bean) throws Exception {
                        mView.ontStateType(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void forConmit(String s) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getConmit(s)
                .compose(RxScheduler.<ConmitData_Bean>Flo_io_main())
                .as(mView.<ConmitData_Bean>bindAutoDispose())
                .subscribe(new Consumer<ConmitData_Bean>() {
                    @Override
                    public void accept(ConmitData_Bean bean) throws Exception {
                        mView.onConmit(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void forJieGuo() {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getjieguo()
                .compose(RxScheduler.<GetJieguoBeen>Flo_io_main())
                .as(mView.<GetJieguoBeen>bindAutoDispose())
                .subscribe(new Consumer<GetJieguoBeen>() {
                    @Override
                    public void accept(GetJieguoBeen bean) throws Exception {
                        mView.onJieGuo(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
